<script lang="ts" setup>
    import { House, ArrowRight, Refresh, Search, RefreshRight, CirclePlus} from "@element-plus/icons-vue"
    import { reactive } from 'vue'
    import { Dept } from "../model/index";
    import { onMounted } from "vue";
    import { useRouter } from "vue-router";
    import deptStore from '../store/DeptStore'
    import createAxios from "../request";

    let axios = createAxios();

    const router = useRouter();

    let list1:Array<Dept> = [];
    let tableData = reactive({
            "list": list1
        });

    const getData = function (){
        axios({
            url: `/deptlist.do`,
            method: "GET"
        }).then((res)=>{
            //请求成功
            tableData.list = res.data;
        }).catch((err)=>{
            //请求失败·
            console.log(err);
        })
    }

    onMounted(() => {
      getData();
    });

    const formInline = reactive({
    user: '',
    region: '',
    date: '',
    })

    const onSubmit = () => {
    console.log('submit!')
    }

    const store = deptStore();

    let jump6_1 = function(){ router.push('/home/deptAdd'); };

    let jump6_2 = function( deptno : number){ 
      store.saveDeptno(deptno);
      router.push('/home/deptUpdate');
    };

    let currentPage = 1
    let gotoFirst = function(){
      currentPage = 1;
    }
    let gotoLast = function(){
      currentPage = tableData.list.length / 10;
    }
</script>

<template>
  <el-container id="mainView">
    <el-header style="background-color: #272822; color: #E5E5E5; line-height: 60px; font-size: 27px;">审批人设定</el-header>
    <el-footer style="height: 30px; line-height: 30px; background-color: #4E5246; border-bottom:1px solid #7A7A7A; border-top:1px solid #7A7A7A;">
      <el-breadcrumb :separator-icon="ArrowRight" style="line-height: 30px;">
        <el-breadcrumb-item :to="{ path: '/home/homepage' }"><el-icon><House /></el-icon>首页</el-breadcrumb-item>
        <el-breadcrumb-item>时间管理</el-breadcrumb-item>
        <el-breadcrumb-item>审批人设定</el-breadcrumb-item>
      </el-breadcrumb>
    </el-footer>
    <el-main style="padding-bottom: 0%;">
        <div class="items">
            <el-form :inline="true" :model="formInline" class="demo-form-inline">
                <el-form-item label="部门名称：" >
                <el-input v-model="formInline.user" clearable />
                </el-form-item>
                <el-form-item>
                <el-button type="primary" @click="onSubmit" color="#0077F2"><el-icon><Search /></el-icon>&nbsp;查询</el-button>
                <el-button type="primary" @click="onSubmit" color="#0077F2"><el-icon><RefreshRight /></el-icon>&nbsp;重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-divider />
        <div class="table">
            
            <el-table :data="tableData.list" border style="width: 96vw;">
                <el-table-column prop="" label="编号" />
                <el-table-column prop="" label="部门名称" />
                <el-table-column prop="" label="考勤审批人" />
                <el-table-column prop="" label="请假审批人" />
                <el-table-column label="操作" >
                  <template #default="scope">
                    <el-button type="warning" @click="jump6_2(scope.row.deptno)" color="#D38A1B" style="color: #FFFFFD;">
                      <el-icon><Refresh /></el-icon>&nbsp;修改
                    </el-button>
                  </template>
                </el-table-column>
            </el-table>
        </div>
        <div style="display: flex; justify-content: flex-end;">
          <el-button type="primary" style="background-color: #262727; border: none;" @click="gotoFirst" >首页</el-button>&nbsp;&nbsp;
          <el-pagination background layout="prev, pager, next" :total="tableData.list.length" style="text-align: right;" v-model="currentPage" />&nbsp;&nbsp;
          <el-button type="primary" style="background-color: #262727; border: none;" @click="gotoLast">尾页</el-button>
        </div>
    </el-main>
  </el-container>
</template>
  
<style scoped>
    #mainView {
        height: 100%;
        width: 100%;
    }

    .demo-form-inline .el-input {
    --el-input-width: 220px;
    }

    .demo-form-inline .el-select {
    --el-select-width: 220px;
    }

    .table {
      display: flex;
      justify-content: center;
    }

    .example-basic .el-date-editor {
      margin: 8px;
    }

</style>
  